package dhc.util;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 *
 * @author wangcj
 * @since 2012-8-14
 * @version 1.0 
 */
public class PoiUtil {
	public static String getStringCellValue(Cell cell){
		String s=null;
		if(cell==null)
			return s;
		switch (cell.getCellType()) {  
			case Cell.CELL_TYPE_STRING:
				s=cell.getStringCellValue();
				break;
			case Cell.CELL_TYPE_NUMERIC:  
				Double dbl=cell.getNumericCellValue();
				s=String.valueOf(dbl.intValue());
				break;
			default:  
				s=cell.toString();
				break;
		}
		return s;
	}
	
	public static int getIntCellValue(Row row ,int index,int defaultValue){
		Cell cell=row.getCell(index);
		if(cell==null)
			return defaultValue;
		Double dbl=cell.getNumericCellValue();
		return dbl.intValue();
	}
	
	public static String getStringCellValue(Row row ,int index){
		Cell cell=row.getCell(index);
		return getStringCellValue(cell);
	}
	
	public static boolean getBooleanCellValue(Row row ,int index){
		Cell cell=row.getCell(index);
		return cell.getBooleanCellValue();
	}
	
}
 